home *** CD-ROM | disk | FTP | other *** search
Text File | 1999-06-25 | 7.5 KB | 297 lines | [TEXT/CWIE] |
- // ===========================================================================
- // CRebootBehavior.cp ©1999 Eric Traut
- // ===========================================================================
-
- #include "CRebootBehavior.h"
- #include "CShadowWindow.h"
-
-
- PixPatHandle CRebootBehavior::sBackgroundPixPat = NULL;
- PicHandle CRebootBehavior::sMacOSPicture = NULL;
- CIconHandle CRebootBehavior::sHappyMacIcon = NULL;
- PicHandle CRebootBehavior::sProgressPicture = NULL;
- PicHandle CRebootBehavior::sSliderPicture = NULL;
- IconSuiteRef CRebootBehavior::sInitIcons[kTotalINITIcons];
- SndListHandle CRebootBehavior::sBootBeepSound = NULL;
- SndChannelPtr CRebootBehavior::sSndChannel = NULL;
-
-
- // ---------------------------------------------------------------------------
- // • CRebootBehavior
- // ---------------------------------------------------------------------------
-
- CRebootBehavior::CRebootBehavior(
- CShadowWindow & inShadowWindow)
- : COffscreenBehavior(inShadowWindow, false, true)
- {
- mCurRebootState = kRebootStateBlackScreen;
- mTicksStateStarted = ::TickCount();
- mTicksInState = GetTicksForState(mCurRebootState);
- }
-
-
- // ---------------------------------------------------------------------------
- // • GetTicksForState
- // ---------------------------------------------------------------------------
-
- void
- CRebootBehavior::DoIdleTask(
- Boolean inGNETime)
- {
- if (inGNETime && mCurRebootState == kRebootStateTearDown)
- {
- // Detach ourselves
- mShadowWindow.DetachBehavior();
- }
- else
- {
- COffscreenBehavior::DoIdleTask(inGNETime);
- }
- }
-
-
- // ---------------------------------------------------------------------------
- // • GetTicksForState
- // ---------------------------------------------------------------------------
-
- UInt32
- CRebootBehavior::GetTicksForState(
- RebootState inState)
- {
- switch (inState)
- {
- case kRebootStateBlackScreen:
- return 60;
- break;
-
- case kRebootStateBootBeep:
- return 0;
- break;
-
- case kRebootStateGrayScreen:
- return 120;
- break;
-
- case kRebootStateHappyMac:
- return 200;
- break;
-
- case kRebootStateMacOSScreen:
- return 600;
- break;
-
- case kRebootStateInit:
- return 900;
- break;
-
- case kRebootStateTearDown:
- return 100000;
- break;
- }
-
- return 0;
- }
-
-
- // ---------------------------------------------------------------------------
- // • CenterRect
- // ---------------------------------------------------------------------------
-
- void
- CRebootBehavior::CenterRect(
- const Rect & inBounds,
- Rect & outCenterRect,
- SInt16 inBoxWidth,
- SInt16 inBoxHeight)
- {
- outCenterRect.left = (inBounds.left + inBounds.right - inBoxWidth) / 2;
- outCenterRect.right = outCenterRect.left + inBoxWidth;
- outCenterRect.top = (inBounds.top + inBounds.bottom - inBoxHeight) / 2;
- outCenterRect.bottom = outCenterRect.top + inBoxHeight;
- }
-
-
- // ---------------------------------------------------------------------------
- // • DrawMacOSScreen
- // ---------------------------------------------------------------------------
-
- void
- CRebootBehavior::DrawMacOSScreen(
- ConstStr255Param inMsgString,
- UInt32 inTicksSinceStart,
- UInt32 inINITsToDraw)
- {
- Rect centerRect;
-
- ::BackPixPat(sBackgroundPixPat);
- ::EraseRect(&mGWorldRect);
- ::PenNormal();
-
- CenterRect(mGWorldRect, centerRect, sMacOSPicture[0]->picFrame.right, sMacOSPicture[0]->picFrame.bottom);
- ::DrawPicture(sMacOSPicture, ¢erRect);
-
- // Draw the progress bar
- CenterRect(mGWorldRect, centerRect, sProgressPicture[0]->picFrame.right, sProgressPicture[0]->picFrame.bottom);
- ::OffsetRect(¢erRect, 0, 90);
- ::DrawPicture(sProgressPicture, ¢erRect);
-
- centerRect.left += 15 - 4;
- centerRect.right = centerRect.left + sSliderPicture[0]->picFrame.right + 4;
- centerRect.top = (centerRect.bottom + centerRect.top - sSliderPicture[0]->picFrame.bottom + 2) / 2;
- centerRect.bottom = centerRect.top + sSliderPicture[0]->picFrame.bottom;
-
- SInt32 timesToRedraw = inTicksSinceStart / 10 + 4;
-
- // Mike Neil told me to comment this
- while (timesToRedraw > 0)
- {
- if (timesToRedraw >= 4)
- {
- timesToRedraw -= 4;
- ::OffsetRect(¢erRect, 4, 0);
- }
- else
- {
- timesToRedraw--;
- ::OffsetRect(¢erRect, 1, 0);
- }
-
- ::DrawPicture(sSliderPicture, ¢erRect);
- }
-
- ::TextFont(systemFont);
- ::TextFace(normal);
- ::TextSize(0);
-
- UInt16 stringWidth = ::StringWidth(inMsgString);
- ::MoveTo((mGWorldRect.left + mGWorldRect.right - stringWidth) / 2,
- (mGWorldRect.top + mGWorldRect.bottom + 142) / 2);
- ::DrawString(inMsgString);
-
- centerRect = mGWorldRect;
- centerRect.bottom -= 16;
- centerRect.top = centerRect.bottom - 32;
- centerRect.left = 20;
- centerRect.right = centerRect.left + 32;
-
- if (inINITsToDraw > kTotalINITIcons)
- inINITsToDraw = kTotalINITIcons;
-
- for (UInt32 iconIndex = 0; iconIndex < inINITsToDraw; iconIndex++)
- {
- ::PlotIconSuite(¢erRect, atNone, kTransformNone, sInitIcons[iconIndex]);
- ::OffsetRect(¢erRect, 50, 0);
- }
- }
-
-
- // ---------------------------------------------------------------------------
- // • RenderToGWorld
- // ---------------------------------------------------------------------------
-
- Boolean
- CRebootBehavior::RenderToGWorld(
- StGWorldLocker & inRenderingLocker)
- {
- #pragma unused (inRenderingLocker)
-
- UInt32 curTicks = ::TickCount();
- UInt32 ticksSinceStart = curTicks - mTicksStateStarted;
- Rect centerRect;
-
- ThrowIfNULL_(sBackgroundPixPat);
- ThrowIfNULL_(sMacOSPicture);
- ThrowIfNULL_(sHappyMacIcon);
-
- switch (mCurRebootState)
- {
- case kRebootStateBlackScreen:
- ::BackColor(blackColor);
- ::EraseRect(&mGWorldRect);
- break;
-
- case kRebootStateBootBeep:
- (void) ::SndPlay(sSndChannel, sBootBeepSound, false);
- break;
-
- case kRebootStateGrayScreen:
- ::ForeColor(blackColor);
- ::BackColor(whiteColor);
- ::PenPat(&qd.gray);
- ::PaintRect(&mGWorldRect);
- break;
-
- case kRebootStateHappyMac:
- ::ForeColor(blackColor);
- ::BackColor(whiteColor);
- ::PenPat(&qd.gray);
- ::PaintRect(&mGWorldRect);
-
- // Draw the happy mac
- CenterRect(mGWorldRect, centerRect, 32, 32);
- ::PlotCIcon(¢erRect, sHappyMacIcon);
- break;
-
- case kRebootStateMacOSScreen:
- DrawMacOSScreen("\pWelcome To MacOS", ticksSinceStart, 0);
- break;
-
- case kRebootStateInit:
- DrawMacOSScreen("\pStarting Up…", ticksSinceStart + GetTicksForState(kRebootStateMacOSScreen) + 200, ticksSinceStart / 100 + 1);
- break;
-
- case kRebootStateTearDown:
-
- break;
- }
-
- // Do we need to switch to the next state in
- // the state machine?
- if (curTicks - mTicksStateStarted >= mTicksInState)
- {
- mCurRebootState++;
- mTicksInState = GetTicksForState(mCurRebootState);
- mTicksStateStarted = curTicks;
- }
-
- return true;
- }
-
-
- // ---------------------------------------------------------------------------
- // • Initialize [static]
- // ---------------------------------------------------------------------------
-
- void
- CRebootBehavior::Initialize(
- SndChannelPtr inSoundChannel)
- {
- sBackgroundPixPat = ::GetPixPat(128);
- Assert_(sBackgroundPixPat != NULL);
-
- sMacOSPicture = ::GetPicture(128);
- Assert_(sMacOSPicture != NULL);
-
- sHappyMacIcon = ::GetCIcon(500);
- Assert_(sHappyMacIcon != NULL);
-
- sProgressPicture = ::GetPicture(129);
- Assert_(sProgressPicture != NULL);
-
- sSliderPicture = ::GetPicture(130);
- Assert_(sSliderPicture != NULL);
-
- for (UInt32 iconIndex = 0; iconIndex < kTotalINITIcons; iconIndex++)
- {
- (void) ::GetIconSuite(&sInitIcons[iconIndex], iconIndex + 128, svAllLargeData);
- Assert_(sInitIcons[iconIndex] != NULL);
- }
-
- sSndChannel = inSoundChannel;
- sBootBeepSound = reinterpret_cast<SndListHandle>(::Get1Resource('snd ', 128));
- Assert_(sBootBeepSound != NULL);
- }
-
-
-
-